package cn.meibang.common.beauty.provider.service;

import cn.apestar.core.base.YesNoEnum;
import cn.apestar.core.framework.exception.BusinessException;
import cn.apestar.core.framework.page.Page;
import cn.meibang.common.beauty.api.IBcoUserProductAPIService;
import cn.meibang.common.beauty.provider.dao.BeautyConsultationOrderUserProductMapper;
import cn.meibang.common.beauty.provider.request.ListRecommendHistoryRequest;
import cn.meibang.common.beauty.provider.response.HistoryRecommendResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by admin on 2017-6-24.
 */
@Service
public class BcoUserProductServiceProvider implements IBcoUserProductAPIService {

    @Autowired
    private BeautyConsultationOrderUserProductMapper bcoUserProductMapper;

    @Override
    public Page<HistoryRecommendResponse> listProduct(ListRecommendHistoryRequest request) {
        if (request.getUserId() == null && StringUtils.isEmpty(request.getOpenid())) {
            throw new BusinessException("user.not.found");
        }
        return listForCountPage(request);
    }

    public Page<HistoryRecommendResponse> listForCountPage(ListRecommendHistoryRequest request) {
        request.setDelFlag(YesNoEnum.Yes.getValue());
        List<HistoryRecommendResponse> items = bcoUserProductMapper.listProduct(request);
        Page<HistoryRecommendResponse> page = request.getPageRecord();
        page.setItems(items);
        return page;
    }
}
